function madiff = madiff(rawdata,nf,ns)

mas = zeros(size(rawdata));
maf = zeros(size(rawdata));

mas(1:ns-1,:) = mean(rawdata(1:ns,:));
maf(1:nf-1,:) = mean(rawdata(1:nf,:));

for i = nf:size(rawdata,1)
    if i>=ns  %assumes ns > nf
        mas(i,:) = mean(rawdata(i-ns+1:i,:));
    end
    maf(i,:) = mean(rawdata(i-nf+1:i,:));
end

madiff = (maf-mas)./rawdata;
return

